package com.s10.ecloud.web.action;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.s10.ecloud.web.Constants;
import com.s10.ecloud.web.model.User;
import com.s10.ecloud.web.service.IUserService;

/**
 * 
 * @author Kevin 用户激活
 */
public class C000002Action extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@SuppressWarnings("restriction")
	@Resource
	private IUserService userService = null;

	@Action(value = "/activateUser", results = {
			@Result(name = "input", location = "/page/ind/registSuccess.jsp"),
			@Result(name = "ind", location = "/page/ind/index.jsp") })
	public String ActivateEntUser() throws Exception {

		User user = userService.updateActiveUser(new Integer(this.getId()),
				this.getPersonalId());

		if (user == null) {
			this.addActionMessage("激活用户不存在，请重新申请，或联系管理员！");
		} else if (user.getRole().getId() == Constants.USER_TYPE_ENT) {
			this.addActionMessage("进入待审核队列，等待管理人员审核通过后才能正常登录");
		} else if (user.getRole().getId() == Constants.USER_TYPE_IND) {
			ActionContext.getContext().getSession()
					.put(Constants.SESSION_KEY_USER, user);

			return "ind";
		}

		return this.INPUT;
	}

	private String id;
	private String personalId;

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the personalId
	 */
	public String getPersonalId() {
		return personalId;
	}

	/**
	 * @param personalId
	 *            the personalId to set
	 */
	public void setPersonalId(String personalId) {
		this.personalId = personalId;
	}
}
